package com.bt.lms.ui.page.classes;

import com.bt.lms.ui.action.divide.plan.BackBtnAction;
import com.bt.lms.ui.action.divide.plan.RandomShiftBtnAction;
import com.bt.lms.ui.vo.ShiftResultProperty;
import com.bt.lms.ui.vo.ViewResultProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Cursor;
import javafx.scene.control.*;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.Background;
import javafx.scene.layout.BackgroundFill;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.FontPosture;
import javafx.scene.text.FontWeight;

import java.util.ArrayList;

/**
 * 预览分班结果页面
 */
public class PreviewShiftResult extends VBox {

    /**
     * 大盒子
     */
    VBox vBox = new VBox();

    /**
     * 宽
     */
    private Integer preWidth = 1280;

    /**
     * 高
     */
    private Integer preHeight = 800;

    public PreviewShiftResult() {
        vBox.setPrefSize(preWidth, preHeight);
        vBox.setSpacing(40);
        vBox.setPadding(new Insets(20));
        vBox.setAlignment(Pos.CENTER);
        Label classLab = new Label("班级情况");
        Font font = Font.font("仿宋", FontWeight.BLACK, FontPosture.REGULAR,30);
        classLab.setFont(font);
        //表格
        TableView classTable = new TableView();
        classTable.setPrefHeight(160);
        //创建列
        TableColumn classIDClu = new TableColumn("班ID");
        classIDClu.setPrefWidth(300);
        TableColumn classNameClu = new TableColumn("班级名称");
        classNameClu.setPrefWidth(300);
        TableColumn stuNumberClu = new TableColumn("学员人数");
        stuNumberClu.setPrefWidth(100);
        TableColumn handleCol = new TableColumn("操作");
        handleCol.setPrefWidth(300);
        //查看学员名单按钮
        HBox hBox = new HBox();
        Button viewBtn= new Button("查看学员名单");
        viewBtn.setCursor(Cursor.HAND); //添加鼠标移入出现小手图案
        Color rgb = Color.rgb(49,193,231);
        BackgroundFill backgroundFill = new BackgroundFill(rgb, null, null); //颜色
        Background background = new Background(backgroundFill);
        viewBtn.setBackground(background);
        viewBtn.setPrefWidth(200);
        hBox.getChildren().add(viewBtn);
        HBox hBox1 = new HBox();
        Button viewBtn1 = new Button("查看学员名单");
        viewBtn1.setCursor(Cursor.HAND); //添加鼠标移入出现小手图案
        viewBtn1.setBackground(background);
        viewBtn1.setPrefWidth(200);
        hBox1.getChildren().add(viewBtn1);
        HBox hBox2 = new HBox();
        Button viewBtn2 = new Button("查看学员名单");
        viewBtn2.setCursor(Cursor.HAND); //添加鼠标移入出现小手图案
        viewBtn2.setBackground(background);
        viewBtn2.setPrefWidth(200);
        hBox2.getChildren().add(viewBtn2);
        //把列放入表头
        classTable.getColumns().addAll(classIDClu,classNameClu,stuNumberClu,handleCol);
        //表中添加数据
        ShiftResultProperty shiftResultProperty01 = new ShiftResultProperty("ID001","班级1",50,hBox);
        ShiftResultProperty shiftResultProperty02 = new ShiftResultProperty("ID002","班级2",60,hBox1);
        ShiftResultProperty shiftResultProperty03 = new ShiftResultProperty("ID003","班级3",120,hBox2);
        ArrayList<ShiftResultProperty> shiftResultProperty = new ArrayList<>();
        shiftResultProperty.add(shiftResultProperty01);
        shiftResultProperty.add(shiftResultProperty02);
        shiftResultProperty.add(shiftResultProperty03);
        //将用户数据集合转换成Javafx组件集合
        ObservableList<ShiftResultProperty> shiftResultProperties = FXCollections.observableArrayList(shiftResultProperty);
        //把数据放入表格当中
        classTable.setItems(shiftResultProperties);
        //配置列映射，让每一列知道要展示的属性是哪一个
        classIDClu.setCellValueFactory(new PropertyValueFactory<ShiftResultProperty,String>("classID"));
        classNameClu.setCellValueFactory(new PropertyValueFactory<ShiftResultProperty,String>("className"));
        stuNumberClu.setCellValueFactory(new PropertyValueFactory<ShiftResultProperty,Integer>("stuNumber"));
        handleCol.setCellValueFactory(new PropertyValueFactory<ShiftResultProperty,HBox>("handle"));

        //按钮盒子
        HBox hBox8 = new HBox();
        hBox8.setSpacing(8);
        hBox8.setAlignment(Pos.CENTER);
        Button confirmedShiftBtn = new Button("确认分班");
        confirmedShiftBtn.setCursor(Cursor.HAND); //添加鼠标移入出现小手图案
        confirmedShiftBtn.setBackground(background);
        //确认分班事件
        BackBtnAction backBtnAction = new BackBtnAction();
        confirmedShiftBtn.setOnAction(backBtnAction);

        Button cancelBtn = new Button("取消");
        cancelBtn.setCursor(Cursor.HAND); //添加鼠标移入出现小手图案
        //取消事件
        RandomShiftBtnAction randomShiftBtnAction = new RandomShiftBtnAction();
        cancelBtn.setOnAction(randomShiftBtnAction);
        hBox8.getChildren().addAll(confirmedShiftBtn,cancelBtn);

        //查看班级学员名单标签
        Label previewClassStuLab = new Label("预览班级学员名单");
        Font font1 = Font.font("仿宋", FontWeight.BLACK, FontPosture.REGULAR,30);
        previewClassStuLab.setFont(font1);
        //班级学员表格
        TableView stuTable = new TableView();
        stuTable.setPrefHeight(160);
        //创建列
        TableColumn iDXClu = new TableColumn("序号");
        iDXClu.setPrefWidth(80);
        TableColumn stuNOClu = new TableColumn("学员编号");
        stuNOClu.setPrefWidth(80);
        TableColumn nameClu = new TableColumn("姓名");
        nameClu.setPrefWidth(80);
        TableColumn genderClu = new TableColumn("性别");
        genderClu.setPrefWidth(120);
        TableColumn studyCenterClu = new TableColumn("学习中心");
        studyCenterClu.setPrefWidth(120);
        TableColumn trainingClu = new TableColumn("培训项目");
        trainingClu.setPrefWidth(120);
        TableColumn epnPlanClu = new TableColumn("招生计划");
        epnPlanClu.setPrefWidth(120);
        TableColumn majorClu = new TableColumn("专业");
        majorClu.setPrefWidth(120);
        TableColumn classNameClu1 = new TableColumn("班级名称");
        classNameClu1.setPrefWidth(120);
        TableColumn mobileNOClu = new TableColumn("手机号码");
        mobileNOClu.setPrefWidth(120);
        TableColumn handleCul1 = new TableColumn("操作");
        handleCul1.setPrefWidth(120);
        //按钮盒子
        HBox hBox3 = new HBox();
        Button shiftBtn = new Button("调整分班");
        shiftBtn.setCursor(Cursor.HAND); //添加鼠标移入出现小手图案
        shiftBtn.setBackground(background);
        hBox3.getChildren().add(shiftBtn);
        HBox hBox4 = new HBox();
        HBox hBox5 = new HBox();
        //表里放入列
        stuTable.getColumns().addAll(iDXClu,stuNOClu,nameClu,genderClu,studyCenterClu,trainingClu,epnPlanClu,majorClu,classNameClu1,mobileNOClu,handleCul1);

        ViewResultProperty viewResultProperty01 = new ViewResultProperty(1,222,"毛旭峰","男","北京","美术设计",2,"美术设计","3班","1552254123",hBox3);
        ViewResultProperty viewResultProperty02 = new ViewResultProperty(2,333,"梁中正","男","江苏","英语培训",2,"","3班","15324556115",hBox4);
        ViewResultProperty viewResultProperty03 = new ViewResultProperty(3,444,"李鹏","男","河南","计算机基础",2,"","3班","16637430212",hBox5);
        //放入集合
        ArrayList<ViewResultProperty> viewResultProperties = new ArrayList<>();
        viewResultProperties.add(viewResultProperty01);
        viewResultProperties.add(viewResultProperty02);
        viewResultProperties.add(viewResultProperty03);
        //将用户数据集合转换成Javafx组件集合
        ObservableList<ViewResultProperty> shiftResultProperties01 = FXCollections.observableArrayList(viewResultProperties);
        //把数据放入表格当中
        stuTable.setItems(shiftResultProperties01);
        //配置列映射，让每一列知道要展示的属性是哪一个
        iDXClu.setCellValueFactory(new PropertyValueFactory<ViewResultProperty,Integer>("iDX"));
        stuNOClu.setCellValueFactory(new PropertyValueFactory<ViewResultProperty,Integer>("stuNO"));
        nameClu.setCellValueFactory(new PropertyValueFactory<ViewResultProperty,String>("name"));
        genderClu.setCellValueFactory(new PropertyValueFactory<ViewResultProperty,String>("gender"));
        studyCenterClu.setCellValueFactory(new PropertyValueFactory<ViewResultProperty,String>("studyCenter"));
        trainingClu.setCellValueFactory(new PropertyValueFactory<ViewResultProperty,String>("training"));
        epnPlanClu.setCellValueFactory(new PropertyValueFactory<ViewResultProperty,Integer>("epnPlan"));
        majorClu.setCellValueFactory(new PropertyValueFactory<ViewResultProperty,String>("major"));
        classNameClu1.setCellValueFactory(new PropertyValueFactory<ViewResultProperty,String>("className"));
        mobileNOClu.setCellValueFactory(new PropertyValueFactory<ViewResultProperty,String>("mobileNO"));
        handleCul1.setCellValueFactory(new PropertyValueFactory<ViewResultProperty,String>("handle"));
        //分页查询
        HBox hBox6 = new HBox();
        hBox6.setSpacing(6);
        hBox6.setAlignment(Pos.CENTER_RIGHT);
        Label firstLab  = new Label("<<首页");
        //颜色
        Color rgb3 = Color.rgb(120,185,0);
        firstLab.setTextFill(rgb3);
        Label lastLab = new Label("<<上一页");
        lastLab.setTextFill(rgb3);
        Button oneLab = new Button("1");
        Button twoLab = new Button("2");
        Button threeLab = new Button("3");
        Button fourLab = new Button("4");
        Label nextLab = new Label("下一页>>");
        nextLab.setTextFill(rgb3);
        Label endLab = new Label("尾页>>");
        endLab.setTextFill(rgb3);
        Label allLab = new Label("总记录数100条");
        TextField pageTF = new TextField();
        pageTF.setPrefWidth(20);
        Label pageLab = new Label("/10");
        Button goBtn = new Button("GO");
        hBox6.getChildren().addAll(firstLab,lastLab,oneLab,twoLab,threeLab,fourLab,nextLab,endLab,allLab,pageTF,pageLab,goBtn);

        //返回按钮
        HBox hBox7 = new HBox();
        hBox7.setAlignment(Pos.CENTER);
        Button backBtn = new Button("返回");
        backBtn.setCursor(Cursor.HAND); //添加鼠标移入出现小手图案
        backBtn.setPrefWidth(100);
        hBox7.getChildren().add(backBtn);
        //返回按钮事件
        RandomShiftBtnAction randomShiftBtnAction1 = new RandomShiftBtnAction();
        backBtn.setOnAction(randomShiftBtnAction1);

        //滚动条
        ScrollPane scrollPane = new ScrollPane();
        scrollPane.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER); //不让设置横滚动条
        scrollPane.setVbarPolicy(ScrollPane.ScrollBarPolicy.ALWAYS);
        scrollPane.setContent(vBox);
        this.getChildren().add(scrollPane);

        //界面添加组件
        vBox.getChildren().addAll(classLab,classTable,hBox8,previewClassStuLab,stuTable,hBox6,hBox7);

    }
}
